package players;

import java.util.HashSet;
import java.util.Set;

public class FutbolPlayer {
    // ********************//
    // /*** Variables ***//
    // ********************//
    private String name;

    private Set<Skill> skills;

    private Integer id;

    // ********************//
    // /*** Constructor ***//
    // ********************//
    public FutbolPlayer(final String name) {
        this.name = name;
        this.skills = new HashSet<Skill>();
    }

    // Constructor vacio para el Hibernate.
    protected FutbolPlayer() {

    }

    // ****************************//
    // /*** Getters and Setters ***//
    // ****************************//
    public Set<Skill> getSkills() {
        return this.skills;
    }

    public void setSkills(final Set<Skill> skills) {
        this.skills = skills;
    }

    public String getName() {
        return this.name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(final Integer id) {
        this.id = id;
    }

    // ****************//
    // /*** Methods ***//
    // ****************//
    /**
     * Agrega una Skill a la lista de skills, si ya hay un skill para la misma posicion se reemplaza.
     */
    public void addSkill(final Skill aSkill) {
        Skill skillPisable = null;
        for (Skill currentSkill : this.skills) {
            if (currentSkill.getPosition() == aSkill.getPosition()) {
                skillPisable = currentSkill;
            }
        }
        this.skills.remove(skillPisable);
        this.skills.add(aSkill);
    }

    /**
     * Devuelve valor de la posicion pasada por parametro obtenido de entre sus habilidades si no posee ninguna
     * habilidad de esa posicion el valor es 0.
     * 
     * @param aPosicion
     * @return value
     */
    public int getValueOfSkill(final Position aPosition) {
        int value = 0;
        for (Skill currentSkill : this.skills) {
            if (currentSkill.getPosition() == aPosition) {
                value = currentSkill.getValue();
                break;
            }
        }
        return value;
    }

    @Override
    public String toString() {
        return this.name;
    }
}
